<?php

abstract class Light_Controller_Front extends Light_Controller
{
    /**
     * @var Light_Database
     */
    protected $_model = null;

    /**
     * Upload path
     * @var string
     */
    protected $_uploadPath = null;

    /**
     * Check if the user has access
     * @var boolean
     */
    protected $_checkAccess = false;

    abstract public function setModel();

    /**
     * Form errors
     * @var array
     */
    public $errors = array();

    public function init()
    {
        parent::init();

        if ($this->_checkAccess && !$this->identity()) {
            $this->view->redirect(array(), 'login');
        }
    }

    public function getModel()
    {
        if ($this->_model === null) {
            $moduleName   = ucfirst($this->getModuleName());
            $modelName    = $moduleName . '_Model_' . $moduleName;
            $this->_model = new $modelName();
        }

        return $this->_model;
    }

    public function downloadfileAction()
    {
        $fileId = (int) $this->getRequest()->getParam('fileId');

        $this->disableTemplate();

        $this->disableView();

        $filesModel = new Default_Model_Files();

        $filesModel->download($fileId);
    }

    public function deletefileAction()
    {
        $fileId = (int) $this->getRequest()->getPost('fileId');

        $this->disableTemplate();

        $this->disableView();

        $filesModel = new Default_Model_Files();

        $fileEntity = $filesModel->delete($fileId);
    }
}